GO

drop table NoteContent;

Create table NoteContent(
hashkey varchar(50),
tabindex int,
noteContent varchar(max),
lastUpdated	datetime)

GO

Alter procedure NoteContent_iu(
@hashkey varchar(50), 
@tabindex int, 
@noteContent varchar(max) )
as
begin
if Exists(select 1 from NoteContent where hashkey = @hashkey and tabindex = @tabindex)
	update NoteContent
	Set NoteContent = @NoteContent,
		lastUpdated = getdate()
	where hashkey = @hashkey
	AND tabindex = @tabindex;
else
	Insert into NoteContent(hashkey, tabindex, noteContent, lastUpdated)
	values
	(
		@hashkey, 
		@tabindex,
		@noteContent,
		getdate()
	);
	
end
		
	
GO



Alter procedure NoteContent_s(
@hashkey varchar(50), 
@tabindex int)
as
begin
Select hashkey, tabindex, NoteContent, lastUpdated from	NoteContent
	where hashkey = @hashkey
	AND tabindex = @tabindex;
end

GO

alter procedure CheckKeyExists(@hashkey varchar(50))
as
begin
	if exists(select 1 from noteContent where hashkey = @hashkey)
		select 1;
	else
		select 0;
end;		
